package DatabaseManaging.Models;

import java.util.ArrayList;
import java.util.Map;


public class LanguageBuilder {
	
	public static LangChan build(String langLine){
		String[] record=langLine.split("\t");
		LangChan langChan=new LangChan();
		langChan.setName(record[1]);
		ArrayList<String> abbs=new ArrayList<String>();
		for(int i=2;i<record.length;i++){
			if(!record[i].isEmpty()){
			abbs.add(record[i]);
			}
		}
		langChan.setAbbs(abbs);
		return langChan;		
	}
	
	public static LangChan build(Map record) {
		LangChan langChan=new LangChan();
		langChan.setId((Long)record.get("language_dim_id"));
		langChan.setName((String)record.get("language_name"));
		ArrayList<String> abbs=new ArrayList<String>();
		for(int i=0;i<5;i++){
			String abbreviation=(String)record.get("language_abbr"+i);
			if(abbreviation!=null && !abbreviation.isEmpty()){
				abbs.add(abbreviation);
			}
		}
		langChan.setAbbs(abbs);

		return langChan;
	}
}
